"use strict";
exports.sendError = function (next, code, result) {
    console.log('Send Error: %j', (code + ", " + result));
    next(null, {
        time: Date.now(),
        code: code,
        result: result,
    });
};
exports.sendResult = function (next, result) {
    next(null, {
        time: Date.now(),
        result: result,
    });
};
exports.getMsgError = function (msg, params) {
    if (msg === undefined) {
        return "msg === undefined";
    }
    for (var i = 0; i < params.length; i++) {
        var param = params[i];
        if (msg[param] === undefined) {
            return "msg[" + param + "] === undefined";
        }
    }
    return "";
};
exports.getTotalDays = function (t) {
    var s = 86400000;
    return Math.floor(t / s);
};
// let errWords = [];
exports.validMessage = function (msg) {
    // for (let i = 0; i < errWords.length; i++) {
    // 	let errMsg = errWords[i];
    // 	msg = msg.replace(errMsg, "**");
    // }
    return msg;
};
/**
 * @see   校验手机号码是否合法
 * @param phone
 */
exports.isPhoneLegal = function (phone) {
    var phoneReg = /^1[34578]\d{9}$/;
    if (phoneReg.test(phone))
        return true;
    return false;
};
exports.formateTime = function (timeDate, fmt) {
    var o = {
        "M+": timeDate.getMonth() + 1,
        "d+": timeDate.getDate(),
        "h+": timeDate.getHours(),
        "m+": timeDate.getMinutes(),
        "s+": timeDate.getSeconds(),
        "q+": Math.floor((timeDate.getMonth() + 3) / 3),
        "S": timeDate.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (timeDate.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
};
/**
 * @see  用户数据库操作  失败
 */
exports.insertDbError = function (err) {
    console.warn(err);
    console.warn("your  data  sync  db   failed !!!");
};
